package com.dinzeer.sjapadder.register;

import cn.mmf.slashblade_addon.SlashBladeAddon;
import com.dinzeer.legendreliclib.lib.compat.slashblade.SlashBladeCreativeTap;
import com.dinzeer.sjapadder.Sjap_adder;
import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.SlashBladeCreativeGroup;
import mods.flammpfeil.slashblade.client.renderer.model.BladeModelManager;
import mods.flammpfeil.slashblade.init.SBItems;
import mods.flammpfeil.slashblade.item.ItemSlashBlade;
import mods.flammpfeil.slashblade.registry.slashblade.SlashBladeDefinition;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.IModBusEvent;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import java.util.Map;

import static com.dinzeer.sjapadder.Sjap_adder.MODID;

public class SjaCreativeTab {
    public static final DeferredRegister<CreativeModeTab> REGISTRY = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
    public static final RegistryObject<CreativeModeTab> SJASlashblade = REGISTRY.register("sjap_adder_slashblade",
            () -> CreativeModeTab.builder()
                    .withTabsBefore(SlashBladeCreativeGroup.SLASHBLADE_GROUP.getId())
                    .title(Component.translatable("item_group.sjap_adder.sjap_adder_slashblade")).icon(() -> {
                        ItemStack stack = new ItemStack(SBItems.slashblade);
                        stack.getCapability(ItemSlashBlade.BLADESTATE).ifPresent(s -> {
                            s.setModel(new ResourceLocation(MODID, "model/kaumyex/kamuyex.obj"));
                            s.setTexture(new ResourceLocation(MODID, "model/kaumyex/life.png"));
                        });
                        return stack;
                    })
                    .displayItems((parameters, tabData) -> {
                        fillBladesForNamespace(parameters, tabData, MODID);
                    })
                    .build());
    public static final RegistryObject<CreativeModeTab> SJAPSlashblade = REGISTRY.register("sjap_slashblade",
            () -> CreativeModeTab.builder()
                    .withTabsBefore(SlashBladeCreativeGroup.SLASHBLADE_GROUP.getId())
                    .title(Component.translatable("item_group.sjap_adder.sjap_slashblade")).icon(() -> {
                        ItemStack stack = new ItemStack(SBItems.slashblade);
                        stack.getCapability(ItemSlashBlade.BLADESTATE).ifPresent(s -> {
                            s.setModel(new ResourceLocation(SlashBladeAddon.MODID, "model/murakumo/model.obj"));
                            s.setTexture(new ResourceLocation(SlashBladeAddon.MODID, "model/murakumo/texture.png"));
                        });
                        return stack;
                    })
                    .displayItems((parameters, tabData) -> {
                        fillBladesForNamespace(parameters, tabData, SlashBladeAddon.MODID);
                    })
                    .build());

    // 新增：统一处理刀剑注册的方法
    private static void fillBladesForNamespace(CreativeModeTab.ItemDisplayParameters features, CreativeModeTab.Output output, String namespace) {
        SlashBladeCreativeTap.fillBladesForNamespace(features, output, namespace);
    }
    
    public static void register(IEventBus a) {
        REGISTRY.register(a);
    }

}
